<?php

namespace Modules\Admin\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ManageRequest extends FormRequest
{


    public function rules()
    {

        switch($this->method())
        {
            // CREATE
            case 'POST':
            {
                return [
                    'name' => 'required|unique:admins,name',
                    'nickname' => 'required|unique:admins,nickname',
                    'gid' => 'required',
                    'rolename' => 'required',
                    'password' => 'required'
                ];
            }
            // UPDATE
            case 'PUT':
            case 'PATCH':
            {

                $id = $this->route() ? $this->route()->manage->id : null;
                return [
                    'name' => 'required|unique:admins,name,'.$id,
                    'nickname' => 'required|unique:admins,nickname,'.$id,
                    'gid' => 'required',
                    'rolename' => 'required',
                ];
            }
            case 'GET':
            case 'DELETE':
            default:
            {
                return [];
            };
        }



    }

    public function messages()
    {
        return [
            'name.required' => '名字不能为空',
            'name.unique' => '名字已经存在',
            'nickname.required' => '昵称不能为空',
            'nickname.unique' => '昵称已经存在',
            'gid.required' => '客户组不能为空',
            'rolename.required' => '角色不能为空',
            'password.required' => '密码不能为空'
        ];
    }

    //权限验证
    public function authorize()
    {
        return true;
    }
}
